import { withUser, json } from "@/lib/api"; import { probeEndpoint, getEndpoint } from "@/lib/endpoints/service"; import { LIMITS } from "@/lib/rate-limit"; export const dynamic = "force-dynamic"; type P = { id: string }; /** POST /api/endpoints/[id]/sync — discover models (`GET {baseUrl}{modelsPath}`) → `{ ok, models: PolyModel[], latencyMs, error?, endpoint }` */ export const POST = withUser

( async ({ user }, { id }) => { const r = await probeEndpoint(user.id, id); return json({ ok: r.ok, models: r.models, latencyMs: r.latencyMs, error: r.error, errorCode: r.errorCode, endpoint: await getEndpoint(user.id, id) }); }, { limit: { ...LIMITS.modelSync, key: "endpoint-sync" } }, );